﻿using Server.Constant;
using Server.Enum;
using Server.Framework.Message;
using Server.Framework.Processor;
using Server.Framework.Service;
using Server.Framework.Socket;
using Server.Message.Request;
using Server.Message.Response;
using Server.Model;
using Server.OptExp;
using Server.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Server.Processor
{
    /// <summary>
    /// Author: Leil
    /// Description: 顶级菜单列表请求处理
    /// CreateTime: 2020/5/31 1:09:15
    /// </summary>
    [ProcessorAttr(MessageId.REQUEST_LOGOUT)]
    class LogoutProcessor : IProcessor
    {
        public void Process(ProtobufAppSession session, RequestBaseMessage message)
        {
            if (message is LogoutReq msg)
            {
                LoginLogService.Instance().UpdateLogoutLog(session.User.ID);
                // 将用户从内存中移除
                UserService.Instance().RemoveUserSession(session.User.ID);
                // 清除session中的User
                session.User = null;
                LogoutResp resp = new LogoutResp(MessageId.RESPONSE_LOGOUT)
                {
                    Code = 200
                };
                session.Send(resp);
            }
        }
    }
}
